import sys
from PySide import QtGui
from PySide import QtCore
from PySide import QtDeclarative
import EXIFQt

class MainWindow(QtGui.QMainWindow):
    
    _pathDirCamera1 = "D:/photosmixersample/fer"
    _pathDirCamera2 = "D:/photosmixersample/male"
    _view = ""
    def __init__(self):
        super(MainWindow,self).__init__()
        #create declarative view
        self._view = QtDeclarative.QDeclarativeView()
        self.initUI()
        
    def initUI(self):
        # create exif variable to using on QML
        exif = EXIFQt.EXIFQt(0)
        
        # create central widget
        central = QtGui.QWidget()
        
        # create layout
        layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom)
        
        
        #set size mode
        self._view.setResizeMode(QtDeclarative.QDeclarativeView.SizeRootObjectToView)
        
        # set exif variable in QML
        self._view.rootContext().setContextProperty('exif',exif)
        self._view.rootContext().setContextProperty('pathCamera1',self._pathDirCamera1)
        self._view.rootContext().setContextProperty('pathCamera2',self._pathDirCamera2)
        
        
        # set qml file to declarative view
        self._view.setSource('./qml/qmlPhotosMixer/qml/qmlPhotosMixer/main.qml')
        
        # add declarative view at layout
        layout.addWidget(self._view)
        
        # create button folder 1
        buttonFolder1 = QtGui.QPushButton("Choose Folder camera 1")
        buttonFolder1.clicked.connect(self.onButtonFolder1Clicked)
        
        # create button folder 2
        buttonFolder2 = QtGui.QPushButton("Choose Folder camera 2")
        buttonFolder2.clicked.connect(self.onButtonFolder2Clicked)
        
        # add buttons to widget
        layout.addWidget(buttonFolder1)
        layout.addWidget(buttonFolder2)
        
        # set layout to central widget
        central.setLayout(layout)

        # set central widget to mainWindow        
        self.setCentralWidget(central)
    
    def onButtonFolder1Clicked(self):
        self._pathDirCamera1 = QtGui.QFileDialog.getExistingDirectory()
        self.updateValueContextProperties()
        print self._pathDirCamera1
        
    def onButtonFolder2Clicked(self):
        self._pathDirCamera2 = QtGui.QFileDialog.getExistingDirectory()
        self.updateValueContextProperties()
        print self._pathDirCamera2
        
    def updateValueContextProperties(self):
        self._view.rootContext().setContextProperty('pathCamera1',self._pathDirCamera1)
        self._view.rootContext().setContextProperty('pathCamera2',self._pathDirCamera2)